export const SIGNUP = 'SIGNUP'
export const SIGNUP_SUCCESS = 'SIGNUP_SUCCESS'
export const SIGNUP_FAIL = 'SIGNUP_FAIL'
export const RESET_SIGNUP = 'RESET_SIGNUP'

export interface SignupPlayload {
  email: string,
  name: string,
  passward: string
}

export interface SignupAction {
  type: typeof SIGNUP,
  payload: SignupPlayload
}

export interface SignupSuccessAction {
  type: typeof SIGNUP_SUCCESS
}

export interface SignupFailAction {
  type: typeof SIGNUP_FAIL,
  message: string
}

export interface ResetSignupAction {
  type: typeof RESET_SIGNUP
}

export const signup = (payload: SignupPlayload):SignupAction => ({
  type: SIGNUP,
  payload
})

export const signupSuccess = ():SignupSuccessAction => ({
  type: SIGNUP_SUCCESS
})

export const signupFail = (message:string):SignupFailAction => ({
  type: SIGNUP_FAIL,
  message
})

export const resetSignup = (): ResetSignupAction=> ({
  type: RESET_SIGNUP
})

/**
 * 登录
 */
export const SIGNIN = 'SIGNIN'
export const SIGNIN_SUCESS = 'SIGNIN_SUCESS'
export const SIGNIN_FAIL = 'SIGNIN_FAIL'

export interface SignPayload {
  email: string,
  password: string
}

export interface SigninAction {
  type: typeof SIGNIN,
  payload: SignPayload
}

export interface SigninSucessAction {
  type: typeof SIGNIN_SUCESS
}

export interface SigninFailAction {
  type: typeof SIGNIN_FAIL,
  message: string
}

export const signin = (payload: SignPayload):SigninAction =>({
  type: SIGNIN,
  payload
})

export const signinSuccess = (): SigninSucessAction=> ({
  type: SIGNIN_SUCESS
})

export const signinFail = (message:string): SigninFailAction=> ({
  type: SIGNIN_FAIL,
  message
})

export type AuthUnionType = 
  | SignupAction 
  | SignupSuccessAction
  | SignupFailAction
  | ResetSignupAction
  | SigninAction
  | SigninSucessAction
  | SigninFailAction